using System;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;

using PartyBoy.TweetMode.Components;

namespace PartyBoy.Modules.TweetMode
{
    public partial class Settings : ModuleSettingsBase
    {

        /// <summary>
        /// handles the loading of the module setting for this
        /// control
        /// </summary>
        public override void LoadSettings()
        {
            try
            {
                if (!IsPostBack)
                {
                    TweetModeSettings settingsData = new TweetModeSettings(this.TabModuleId);
                    if (settingsData.ConsumerKey != null)
                        txtConsumerKey.Text = settingsData.ConsumerKey;
                    if (settingsData.ConsumerSecret != null)
                        txtConsumerSecret.Text = settingsData.ConsumerSecret;
                    txtTweetCount.Text = settingsData.Count.ToString();
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        /// <summary>
        /// handles updating the module settings for this control
        /// </summary>
        public override void UpdateSettings()
        {
            try
            {
                TweetModeSettings settingsData = new TweetModeSettings(this.TabModuleId);
                settingsData.ConsumerKey = txtConsumerKey.Text;
                settingsData.ConsumerSecret = txtConsumerSecret.Text;
                settingsData.Count = Convert.ToInt32(txtTweetCount.Text);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
    }
}